package com.liupei.base.entity;

import com.liupei.enums.ResultCode;

import java.io.Serializable;

/**
 * 这个和ResultBean 效果一样
 * @ClassNameResult
 * @Description
 * @Author liupei
 * @Emaile 3268727800@qq.com
 * @Date2021/3/12 16:47
 * @Version V1.0
 **/
public class Result implements Serializable {
    private Integer code;
    private String msg;
    private Object data;

    /**
     *  返回200
     * @return
     */
    public static Result ok(){
        return new Result(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMsg());
    }

    /**
     * 返回成功得结果 200,
     */
    public static Result ok(Object data) {
        return new Result(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg(), data);
    }

    //使用EnumCode 自定义
    public static Result ok(ResultCode code, Object data) {
        return new Result(code.getCode(),code.getMsg(),data);
    }

    //使用EnumCode 自定义
    public static Result ok(ResultCode code) {
        return new Result(code.getCode(), code.getMsg(),  null);
    }
    //使用自定义参数
    public static Result ok(int code,String msg , Object data) {
        return new Result(code, msg,  data);
    }


    //返回错误的结果 500
    public static Result error() {
        return new Result( ResultCode.ERROR.getCode(),ResultCode.ERROR.getMsg(), null);
    }

    public static Result error(ResultCode code) {
        return new Result(code.getCode(),code.getMsg(),  null);
    }

    public static Result error(int code, String msg) {
        return new Result(code,msg, null);
    }


    public Result() {
    }

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
}
